package com.macro.cloud.controller;

/**
 * 字段换行分组工具类
 */
public class SqlColumnSplitUtils {


    public static void main(String[] args) {
        String src = "t.absassetsrc_asset_section_sid,\n" +
                "             t.report_date,\n" +
                "             t.contract_no,\n" +
                "             t.loan_usage,\n" +
                "             t.initiating_agency,\n" +
                "             t.mortgage_rank,\n" +
                "             t.loan_date,\n" +
                "             t.loan_due_date,\n" +
                "             t.contract_amount,\n" +
                "             t.loantovalue_ratio,\n" +
                "             t.down_payment_amount,\n" +
                "             t.contract_duration,\n" +
                "             t.execution_rate,\n" +
                "             t.base_rate,\n" +
                "             t.floating_value,\n" +
                "             t.floating_percent,\n" +
                "             t.rate_type,\n" +
                "             t.rate_adjust_frequency,\n" +
                "             t.acting_dealer,\n" +
                "             t.repayment_method,\n" +
                "             t.guarantor,\n" +
                "             t.borrower_number,\n" +
                "             t.borrower_type,\n" +
                "             t.borrower_name,\n" +
                "             t.certificate_type,\n" +
                "             t.certificate_number,\n" +
                "             t.nationality,\n" +
                "             t.residence,\n" +
                "             t.birthday,\n" +
                "             t.sex,\n" +
                "             t.age,\n" +
                "             t.profession,\n" +
                "             t.annual_income,\n" +
                "             t.marital_status,\n" +
                "             t.affiliate_staff,\n" +
                "             t.credit_score,\n" +
                "             t.collateral_value,\n" +
                "             t.currency,\n" +
                "             t.repayment_frequency,\n" +
                "             t.guarantee_method,\n" +
                "             t.guarantee_method2,\n" +
                "             t.guarantee_method3,\n" +
                "             t.guarantee_method4,\n" +
                "             t.guarantee_method5,\n" +
                "             t.vehicle_mortgage,\n" +
                "             t.estate_mortgage_type,\n" +
                "             t.mortgage_registration,\n" +
                "             t.provincename,\n" +
                "             t.cityname,\n" +
                "             t.business_category,\n" +
                "             t.business_model,\n" +
                "             t.contract_main_unit,\n" +
                "             t.vehicle_main_unit,\n" +
                "             t.vehicle_type,\n" +
                "             t.transport_work_years,\n" +
                "             t.enterprise_size,\n" +
                "             t.business_scope,\n" +
                "             t.main_business,\n" +
                "             t.loan_balance,\n" +
                "             t.paid_period,\n" +
                "             t.remaining_period,\n" +
                "             t.first_repayment_date,\n" +
                "             t.repayment_day,\n" +
                "             t.fivelevel_classification,\n" +
                "             t.fivelevel_audit_date,\n" +
                "             t.cur_overdue_days,\n" +
                "             t.cur_overdue_principal,\n" +
                "             t.cur_overdue_interest,\n" +
                "             t.cum_overdue_times,\n" +
                "             t.avg_overdue_days,\n" +
                "             t.max_overdue_days,\n" +
                "             t.accum_overdue_principal,\n" +
                "             t.accum_overdue_interest,\n" +
                "             t.accum_overdue_days,\n" +
                "             t.access_date,\n" +
                "             t.create_dt,\n" +
                "             t.create_by,\n" +
                "             t2.asset_status,\n" +
                "             apd.audit_result";

        int numbersOfOneline = 5; //一行5个字段
        splitLine(src, numbersOfOneline);
    }


    /**
     * 字段换行 N个字段分一组
     *
     * @param src
     */
    private static void splitLine(String src, int numbersOfOneline) {
        String[] split = src.split("\n");
        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < split.length; i++) {
            if ((i + 1) % numbersOfOneline == 0) {
                //换行保留换行符
                sb.append(split[i].trim()).append("\n");
            } else {
                //不换号则保留一个空格
                sb.append(split[i].trim()).append(" ");
            }
        }
        System.out.println("-------running---start----------");
        System.out.println(sb.toString());
        System.out.println("-------running--end-----------");
    }
}
